﻿
using System;
using Nancy.Hosting.Self;

namespace QQ2564874169.WebFx.Nancy
{
    public class FxStartup
    {
        private NancyHost _host;

        public void Start()
        {
            if (_host != null)
            {
                throw new Exception("不能重复启动");
            }

            var baseUrl = "http://localhost:" + GetPort();
            _host = new NancyHost(GetHostConfiguration(), new Uri(baseUrl));
            _host.Start();
        }

        protected virtual HostConfiguration GetHostConfiguration()
        {
            return new HostConfiguration { UrlReservations = new UrlReservations { CreateAutomatically = true } };
        }

        protected virtual int GetPort()
        {
            return 8000;
        }
    }
}
